<template>
  <div>
    <van-field
      v-bind="$attrs"
      v-on="$listeners"
      readonly
      :name="label"
      :value="value"
      :label="label"
      :placeholder="placeholder || `请选择${label}时间`"
      @click="showPopup"
      :disabled="disabled"
      :is-link="!disabled"
    />
    <VantDataTimePopup
      v-bind="{...$props,...$attrs}"
      v-on="$listeners"
      ref="VantDataTimePopupRef"
      v-model="syncValue"
    ></VantDataTimePopup>
  </div>
</template>

<script>
import VantDataTimePopup from '../VantDataTimePopup'
export default {
  name: 'VanFieldDatetimePicker',
  components: { VantDataTimePopup },
  model: {
    prop: 'value',
    event: 'update:value'
  },
  props: {
    placeholder: {
      type: String,
      default: ''
    },
    label: {
      type: String,
      default: '时间选择'
    },
    type: {
      type: String,
      default: 'date'
    },
    title: {
      type: String,
      default: '选择年月日'
    },
    value: {
      type: String,
      default: ''
    },
    format: {
      type: String,
      default: 'YYYY-MM-DD'
    },
    disabled: {
      type: Boolean,
      default: false
    }
  },
  computed:{
    syncValue:{
      get(){
        return this.value
      },
      set(val){
        this.$emit('update:value',val)
      }
    }
  },
  methods: {
    showPopup(){
      this.$refs.VantDataTimePopupRef.open()
    }
  }
}
</script>

<style scoped lang="scss">

</style>
